package org.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

/**
 * @Author: fzykd
 * Date: 2024/5/7
 * Thread: 21:12
 * User: LQH
 */

//浏览器操作
public class Browser {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "E:/software/Java/bin/chromedriver.exe");

        //谷歌驱动创建
        ChromeOptions options = new ChromeOptions();
        //引入谷歌驱动
        //允许所有请求
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        //启动需要打开的网页
        webDriver.get("https://www.baidu.com");
        //输入情人节
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("情人节");
        //点击搜索
        webDriver.findElement(By.cssSelector("#su")).click();
        //浏览器刷新
        Thread.sleep(3000);
        webDriver.navigate().refresh();
        //浏览器后退一步
        Thread.sleep(3000);        //加个休眠时间方便观察
        webDriver.navigate().back();
        //浏览器前进
        Thread.sleep(3000);
        webDriver.navigate().forward();
        //浏览器窗口最大化
        webDriver.manage().window().maximize();
        Thread.sleep(2000);
        //浏览器窗口按照指定大小来显示
        webDriver.manage().window().setSize(new Dimension(500,500));
        Thread.sleep(3000);
        //浏览器全屏
        webDriver.manage().window().fullscreen();
        Thread.sleep(3000);



        webDriver.quit();

    }
}
